<?php


namespace App\Transformers\User;

use App\Models\UserExtract;
use League\Fractal\TransformerAbstract;

class UserExtractsTransformer extends TransformerAbstract
{
    //可进行包含的信息
    protected $availableIncludes = [
        'user'
    ];

    public function transform(UserExtract $userExtract)
    {
        return [
            'id' => $userExtract->id,
            'user_id' => $userExtract->user_id ?? '',
            'real_name' => $userExtract->real_name ?? '',
            'extract_type' => $userExtract->extract_type ?? '',
            'extract_typec' => $userExtract->extractTypeEnum[$userExtract->extract_type] ?? '',
            'bank_code' => $userExtract->bank_code ?? '',
            'bank_address' => $userExtract->bank_address ?? '',
            'alipay_code' => $userExtract->alipay_code ?? '',
            'extract_price' => $userExtract->extract_price ?? '',
            'remarks' => $userExtract->remarks ?? '',
            'balance' => $userExtract->balance ?? '',
            'fail_msg' => $userExtract->fail_msg ?? '',
            'fail_time' => $userExtract->fail_time ?? '',
            'status' => $userExtract->status ?? '',
            'status_type' => $userExtract->statusEnum[$userExtract->status] ?? '',
            'wechat_code' => $userExtract->wechat_code ?? '',
            'qrcode_url' => $userExtract->qrcode_url ?? '',
            'created_at' => $userExtract->created_at ? $userExtract->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $userExtract->updated_at ? $userExtract->updated_at->format("Y-m-d H:i:s") : '',
        ];
    }

    public function includeUser(UserExtract $userExtract)
    {
        return $this->item($userExtract->user, new UserTransformer());
    }
}
